#include "engine.h"
#include "SDL/SDL.h"
#include <iostream>
#include "image.h"

using namespace std;

/* ====================== Ball Class ===================== */

void BallClass::DrawBall(SDL_Surface* scrn){
  apply_surface(Location.x, Location.y, model, scrn);
}

void BallClass::Init(){
  BreakAble=true;
  destroyed = false;
  exsist = false;
  random();
  color = rand()%5;
  Location.x = 0;
  Location.y = 0;
  switch(color) {
  case 0:
    model = load_bmp("./img/blaa.bmp");
    break;
  case 1:
    model = load_bmp("./img/gul.bmp");
    break;
  case 2:
    model = load_bmp("./img/test.bmp");
    break;
  case 3:
    model = load_bmp("./img/gron.bmp");
    break;
  case 4:
    model = load_bmp("./img/red.bmp");
    break;
  }

}

void BallClass::Free(){
 
}

void BallClass::RemoveBall(SDL_Surface* scrn){
	SDL_Surface* clear = load_bmp("./img/rmbold.bmp");
	apply_surface(Location.x, Location.y,clear,scrn);
	SDL_FreeSurface(clear);
}

/* ======================= Player Class ======================*/

void PlayerClass::Shoot(){

}

void PlayerClass::Catch(){
  
}

void PlayerClass::setBallColor(int i){
	if (i < 5) {
		BallColor = i;
	}
}

int PlayerClass::getBallColor(){
	return BallColor;
}

void PlayerClass::RemoveTrace(SDL_Surface* scrn){
  SDL_Surface* clear = load_bmp("./img/rmbold.bmp");
  apply_surface(Location.x, Location.y,clear,scrn);
  SDL_FreeSurface(clear);
}

void PlayerClass::MoveLeft(){
  BallPos--;
  Location.x -= 50;
  MoveToSurface(Location.x);
  // Update();
}

void PlayerClass::MoveRight(){
  BallPos++;
  Location.x += 50;
  MoveToSurface(Location.x);
  // Update();
}

void PlayerClass::Init(){
  Location.y = 430;
  Location.x = 6*50; 
  model = load_bmp("./img/player.bmp");
  BallColor = 0;
  BallPos = 6;
  gotBall = false;
  cout << "Player created succesfully!" << endl << flush;
}

void PlayerClass::MoveToSurface(int locX){
  SDL_Rect offset;
  // int i = model->w/2;
  // Location.x = locX - i; // Location.x = center of ball - center of player!
  offset.x = Location.x;
  offset.y = Location.y;
  // Update
}

void PlayerClass::Draw(SDL_Surface* scrn){
  apply_surface(Location.x, Location.y, model, scrn);
}

/* ====================================== Event Handler ======================== ***/

void EventHandler::KeyPressed(char key){


}

void EventHandler::HandleEvent(SDL_Event event){
  if (event.type == SDL_KEYDOWN){
    switch(event.key.keysym.sym){
    case SDLK_UP:
      cout << "Up is Pressed" << endl << flush;
      break;
    case SDLK_DOWN:
      
      break;
    case SDLK_RIGHT:
      
      break;
    case SDLK_LEFT:
      
      break;
      
    }
  }
  
}

/* ======================================== End of events ! =) ============================ */



int CenterOfBall(int BallX, SDL_Surface* src){
  cout << "X + Surface_Height / 2\n" << flush;
  int x = BallX;
  int i = src->w/2;
  x += i;
  cout << "Center = " << x << endl << flush;
  return x;
}
